package com.wswy.wzcx.ui.pay

import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.os.Bundle
import android.text.SpannableString
import android.text.SpannableStringBuilder
import android.text.style.ForegroundColorSpan
import com.blankj.utilcode.util.AppUtils
import com.che.libcommon.utils.ToastUtils
import com.wswy.wzcx.R
import com.wswy.wzcx.module.base.CBaseFragment
import com.wswy.wzcx.module.base.getColor
import com.wswy.wzcx.module.base.onClick
import com.wswy.wzcx.ui.Constants
import kotlinx.android.synthetic.main.fragment_kf_service.*


class KfServiceFragment : CBaseFragment() {

    override fun getContentLayoutId(): Int {
        return R.layout.fragment_kf_service
    }

    override fun getFragmentTitle(): String {
        return "联系客服"
    }

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)

        val wechat = arguments?.getString(Constants.EXTRA_DATA)?: "chewufuwuhao"

        tv_wx.text = SpannableStringBuilder().apply {
            append(getString(R.string.kf_wechat_hint))
            append(SpannableString(wechat).apply {
                setSpan(ForegroundColorSpan(getColor(R.color.colorPrimary)),0,length,SpannableString.SPAN_INCLUSIVE_EXCLUSIVE)
            })
        }

        //复制
        btn_copy.onClick {

            kotlin.runCatching {

                val clipboardManager = it.context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
                clipboardManager.primaryClip = ClipData.newPlainText(null, wechat)
                ToastUtils.showText("已复制")
            }

        }

        //打开微信
        btn_open_wx.onClick {

            kotlin.runCatching {
                AppUtils.launchApp("com.tencent.mm")
            }

        }
    }

}